package com.hey.baseapplication.bean;

import android.util.Log;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * Created by Hey on 16/12/15.
 */

public class User {
    private String user_id;
    private String nickname;
    private String avatar;
    private String basic_certificate;
    private String jiehuo_certificate;
    private String rongcloud_token;
    private int id;
    public String getUser_id() {
        return user_id;
    }

    public void setUser_id(String user_id) {
        this.user_id = user_id;
    }

    public String getNickname() {
        return nickname;
    }

    public void setNickname(String nickname) {
        this.nickname = nickname;
    }

    public String getAvatar() {
        return avatar;
    }

    public void setAvatar(String avatar) {
        this.avatar = avatar;
    }

    public String getBasic_certificate() {
        return basic_certificate;
    }

    public void setBasic_certificate(String basic_certificate) {
        this.basic_certificate = basic_certificate;
    }

    public String getJiehuo_certificate() {
        return jiehuo_certificate;
    }

    public void setJiehuo_certificate(String jiehuo_certificate) {
        this.jiehuo_certificate = jiehuo_certificate;
    }

    public String getRongcloud_token() {
        return rongcloud_token;
    }

    public void setRongcloud_token(String rongcloud_token) {
        this.rongcloud_token = rongcloud_token;
    }


    /**
     * 根据参数名赋值
     * @param key 参数
     * @param value 值
     * @return
     */
    public User setValueByKey(String key, Object value) {
        //1.根据key调用类中的方法进行赋值
//      //获取类中声明的方法
//        Method method[]=this.getClass().getDeclaredMethods();
//          遍历方法获得含有key并且为set的方法名
// for (int i=0;i<method.length;i++){
//            if (method[i].getName().toLowerCase().contains(key.toLowerCase())&&method[i].getName().contains("set")){
//                Method method1=method[i];
//                try {
//        //调用方法
//                    method1.invoke(this,value);
//                } catch (IllegalAccessException e) {
//                    e.printStackTrace();
//                } catch (InvocationTargetException e) {
//                    e.printStackTrace();
//                }
//            }
//        }
        //2.根据参数名直接进行赋值
        //获得类中声明的参数
        Field names[] = this.getClass().getDeclaredFields();
        //遍历参数名取得与key相同的参数并进行赋值
        for (int i = 0; i < names.length; i++) {
            if (names[i].getName().toLowerCase().equals(key.toLowerCase())) {
                names[i].setAccessible(true);
                try {
                    names[i].set(this, value);
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                }
            }
        }
        return this;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }
}
